# 移除并替换有问题的代码区域
import os

# 文件路径
file_path = r'd:\未知\yolo_apply\video_processing\video_processor.py'

# 读取文件内容
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
    lines = f.readlines()

# 创建新的内容列表
new_lines = []
skip_mode = False
problem_start_line = -1
problem_end_line = -1

# 查找问题区域的开始和结束行
for i, line in enumerate(lines):
    if '# 错误率过高时触发警告和恢复' in line:
        problem_start_line = i
        skip_mode = True
        new_lines.append(line)  # 保留注释
        # 添加一个非常简单的替代代码
        new_lines.append('                # 简单的错误率检查逻辑\n')
        new_lines.append('                import time\n')
        new_lines.append('                current_time = time.time()\n')
        new_lines.append('                if error_count > 10:\n')
        new_lines.append('                    import logging\n')
        new_lines.append('                    logging.warning("High error rate detected")\n')
        new_lines.append('                    error_count = 0\n')
    elif skip_mode and 'error_count = 0' in line:
        problem_end_line = i
        skip_mode = False
    elif not skip_mode:
        new_lines.append(line)

print(f"找到问题区域从第{problem_start_line+1}行到第{problem_end_line+1}行")
print(f"替换了{problem_end_line - problem_start_line + 1}行代码")

# 写回文件
with open(file_path, 'w', encoding='utf-8', newline='\n') as f:
    f.writelines(new_lines)

print(f"已移除并替换问题代码区域")
print("现在让我们再次尝试编译...")